<template>
  <view class="cardBag">
    <view class="box">
      <view class="card flex-a" v-for="(item, index) in list" :key="item.id" :style="'background:#' + item.color"
        @click="jumpTo('/packageA/pages/petID/index?id=' + item.id)">
        <view class="pic">
          <image src="https://cxj.szzkba.cn/up/uploadPath/icon/pPt0BSP.png" v-if="item.petType == 1" mode="widthFix" />
          <image src="https://cxj.szzkba.cn/up/uploadPath/icon/pPaqXAU.png" v-if="item.petType == 0" mode="widthFix" />
        </view>
        <view class="info">
          <view class="name">昵称：<text>{{ item.petName }}</text></view>
          <view class="sex">性别：<text>{{ item.petSex == 0 ? '弟弟' : item.petSex == 1 ? '妹妹' : '' }}</text>
          </view>
          <view class="bir">生日：<text>{{ item.petDate }}</text></view>
        </view>
        <div class="right">
          <Right color="#fff" />
        </div>
      </view>
    </view>
    <div class="add-pet flex-a" @click="jumpTo('/packageA/pages/petID/index')">
      <div class="left">+</div>
      <div class="right">
        <div>添加宠物</div>
        <div>开启宠物卡 享多项特权</div>
      </div>
    </div>
  </view>
</template>

<script>
import Taro, { useRouter } from '@tarojs/taro';
import { reactive, toRefs, onMounted } from 'vue';
import { Right } from '@nutui/icons-vue-taro';
import { getPetList } from '../../../api/index'

export default {
  name: 'pet',
  components: {
    Right
  },
  setup() {
    const data = reactive({
      list: []
    });

    onMounted(() => {
      getPetList().then(res => {
        if (res.resultCode == 200) {
          let list = res.data
          list.forEach(item => {
            item.color = Math.floor(Math.random() * 16777215).toString(16)
          })
          data.list = list
        }
      })
    });

    const jumpTo = (path) => {
      Taro.navigateTo({ url: path });
    }
    return {
      ...toRefs(data), jumpTo,
    }
  }
}
</script>
<style lang="scss">
.cardBag {
  padding: 20rpx;
  min-height: 100vh;
  background: #F9F9F9;

  .box {

    .card {
      border-radius: 20rpx;
      background: #FC6B73;
      padding: 10rpx 20rpx 0;
      margin-bottom: 20rpx;

      .pic {
        width: 150rpx;
        text-align: center;

        image {
          width: 100rpx;
        }
      }

      .info {
        width: 70%;
        font-weight: bold;
        font-size: 28rpx;
        color: rgba(255, 255, 255, 0.7);
        white-space: nowrap;

        view {
          margin-bottom: 10rpx;
          letter-spacing: 4rpx;

          text {
            display: inline-block;
            width: 100rpx;
            height: 30rpx;
            line-height: 30rpx;
            padding-left: 10rpx;
            border-radius: 5rpx;
            margin-left: 20rpx;
          }
        }
      }
    }
  }

  .card-title {
    margin-bottom: 20rpx;
  }

  .card-list {
    .card-item {
      height: 150rpx;
      border-radius: 10rpx;
      background: rgba(0, 0, 0, 0.3);
      color: #fff;
      padding: 20rpx;
      box-sizing: border-box;
      margin-bottom: 20rpx;

      image {
        width: 100rpx;
        height: 100rpx;
        border-radius: 10rpx;
        background: darkred;
        margin-right: 20rpx;
      }

      .title {
        font-size: 28rpx;
        margin-bottom: 5rpx;
      }

      .txt {
        font-size: 20rpx;
      }
    }
  }

  button {
    width: calc(100% - 40rpx);
    background: #1777FF;
    height: 80rpx;
    line-height: 80rpx;
    letter-spacing: 8rpx;
    font-size: 30rpx;
    position: fixed;
    bottom: 20rpx;
  }

  .add-pet {
    background: #fff;
    margin: 20rpx auto 0;
    border-radius: 10rpx;
    padding: 20rpx;
    box-sizing: border-box;

    .left {
      margin-right: 20rpx;
      color: #0B7AFC;
      font-weight: bold;
      font-size: 60rpx;
      padding: 25rpx 40rpx;
      background: #EAF4FE;
      border-radius: 5rpx;
    }

    .right {
      div:first-child {
        color: #9B9B9B;
        font-size: 32rpx;
        margin-bottom: 10rpx;
        font-weight: bold;
      }

      div:last-child {
        color: #9C9C9C;
        font-size: 24rpx;
        font-weight: bold;
      }
    }
  }
}
</style>
